package com.xx.job.service.system.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xx.job.common.PageResult;
import com.xx.job.controller.dto.PageDTO;
import com.xx.job.entity.system.SysTables;
import com.xx.job.mapper.SysTablesMapper;
import com.xx.job.service.system.SysTablesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liangcy
 * @since 2021-01-14
 */
@Service
public class SysTablesServiceImpl extends ServiceImpl<SysTablesMapper, SysTables> implements SysTablesService {

    @Autowired
    private SysTablesMapper sysTablesMapper;

    @Override
    public int add(SysTables sysTables) {
        return sysTablesMapper.insert(sysTables);
    }

    @Override
    public int delete(Long id) {
        return sysTablesMapper.deleteById(id);
    }

    @Override
    public int update(SysTables sysTables) {
        return sysTablesMapper.updateById(sysTables);
    }

    @Override
    public SysTables select(Long id) {
        return sysTablesMapper.selectById(id);
    }

    @Override
    public IPage<SysTables> selectPage(PageDTO pageDTO, SysTables sysTables) {
        IPage<SysTables> page = new Page<>(pageDTO.getPageIndex(),pageDTO.getPageSize());
        QueryWrapper<SysTables> wrapper = new QueryWrapper<>();
        if(StringUtils.isNotBlank(sysTables.getTableName())){
            wrapper.like("table_name",sysTables.getTableName().trim());
        }
        if(StringUtils.isNotBlank(sysTables.getTableComment())){
            wrapper.like("table_comment",sysTables.getTableComment());
        }
        IPage<SysTables> sysTablesIPage = sysTablesMapper.selectPage(page, wrapper);
        return sysTablesIPage;
    }
}
